﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

//using System.Windows.Forms.Timer;

//namespace Calendar.Net
namespace WindowsFormsApplication1
{
    public partial class calendar : Form
    {
        public bool check_conflect(int from, int to, string day, string month, string year)
        {
            SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\elkolyaa\calendar-maintainer-508c42534a4c\calendar-maintainer-508c42534a4c\WindowsFormsApplication1\WindowsFormsApplication1\usersDB.mdf;Integrated Security=True");

            SqlCommand cmd = cn.CreateCommand();
            SqlDataReader data = null;

            cn.Open();
            int start_time = 0, end_time = 0;
            cmd.CommandText = "select event_timefrom from users where (event_numDay =" + day + ") and (event_month = " + month + ") and (event_year = " + year + ")";
            data = cmd.ExecuteReader();
            while (data.Read())
            {
                start_time = data.GetInt32(0);

            }

            data.Close();
            cmd.CommandText = "select event_timeto from users where (event_numDay =" + day + ") and (event_month = " + month + ") and (event_year = " + year + ")";
            data = cmd.ExecuteReader();
            while (data.Read())
            {
                end_time = data.GetInt32(0);

            }

            if (start_time == from || end_time == to)
                return false;

            else if (start_time > from && end_time < to)
                return false;
            else
                return true;
        }



        public calendar()
        {
            InitializeComponent();
 
            for (int x = 0; x < 31; x++)
            {
                days.Items.Add(x + 1);

            }
            for (int m = 0; m < 12; m++)
            {
                month.Items.Add(m + 1);

            }

            for (int y = 1990; y < 2050; y++)
            {
                year.Items.Add(y + 1);

            }
            for (int z = 0; z < 24; z++)
            {
                time.Items.Add(z + 1);

            }
           
        }


       public static int Days;
       public static int Month;
       public static string Year;
       public static int Time; 

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
         
                select_dayNum.Text = monthCalendar1.SelectionStart.Day.ToString();
                select_dayName.Text = monthCalendar1.SelectionStart.DayOfWeek.ToString();
                select_month.Text = monthCalendar1.SelectionStart.Month.ToString();
                select_year.Text = monthCalendar1.SelectionStart.Year.ToString();
            

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
           String time = DateTime.Now.ToLongTimeString();
            label1.Text = time;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Days = days.SelectedIndex + 1;
            Month = month.SelectedIndex + 1;
            Year = this.year.GetItemText(this.year.SelectedItem);
            Time = time.SelectedIndex + 1;
            outSide_show ob = new outSide_show();

            if (Time == 0 | Month == 0 | Days == 0)
            {
                MessageBox.Show("please enter the time or the date and the time for event", "Error");
            }
            else
            {
                ob.SHow(Days, Month, Year, Time);

            }

        }

        private void groupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            add_group addgroup = new add_group();
            addgroup.label5.Text = this.select_dayNum.Text;
            addgroup.label6.Text = this.select_dayName.Text;
            addgroup.label7.Text = this.select_month.Text;
            addgroup.label8.Text = this.select_year.Text;
            addgroup.Show();
        }

        private void individualToolStripMenuItem_Click(object sender, EventArgs e)
        {
            add_individual indform = new add_individual();
            indform.label4.Text = this.select_dayNum.Text;
            indform.label5.Text = this.select_dayName.Text;
            indform.label6.Text = this.select_month.Text;
            indform.label7.Text = this.select_year.Text;
            indform.Show();

        }

        private void showToolStripMenuItem_Click(object sender, EventArgs e)
        {
            inSide_Show obj = new inSide_Show();
            obj.label4.Text = this.select_dayNum.Text;
            obj.label5.Text = this.select_dayName.Text;
            obj.label6.Text = this.select_month.Text;
            obj.label7.Text = this.select_year.Text;
            obj.shoow();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void year_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void ddd_Click(object sender, EventArgs e)
        {

        }

        private void calendar_Load(object sender, EventArgs e)
        {

        }

       
    }
}
